import IndexBannner from "../components/indexBanner/indexBanner";

class HomeBanner {
    constructor({id, picUrl, type}){
        this.picUrl=picUrl; // 轮播图地址
        this.id=id; // 歌曲id
        this.type=type; // 歌曲类型
    }
}

const createHomeBanner = (banners)=>{

    return new HomeBanner({
        picUrl:banners.picUrl,
        id:banners.id,
        type:banners.type,
    })
}

export const formatHomeBanner = (banners)=>{
    let arr = [];
    banners.forEach( (item,index)=>{
        arr.push( createHomeBanner(item) )
    } );
    return arr;
}

export const formatDate = (date)=>{
    return date<10?`0${date}`:date;
}

export const formatMonthDate = (time)=>{
    let times = new Date(time);
    const months = formatDate(times.getMonth()+1);
    const day = formatDate(times.getDate());
    return  `${months}月${day}日`
}

export const formatYearMonthDate=(time)=>{
    let times = new Date(time);
    const years = times.getFullYear();
    const months = formatDate(times.getMonth()+1);
    const day = formatDate(times.getDate());
    return  `${years}.${months}.${day}`
}


export const formatSongTime = (dt)=>{
    let time = dt / 1000;
    let minute = Math.floor(dt / 60) % 60;
    minute = minute.toString().padStart(2, "0");
    let second = Math.floor(dt) % 60;
    second = second.toString().padStart(2, "0");
    return `${minute}:${second}`;
}


export const formatHotCommentPublishTime = (time)=>{
    //传进来的是评论时间,是一个毫秒数
    const passDt = new Date(time);
    const passYears = passDt.getFullYear();
    const passMonths = passDt.getMonth()+1;
    const passDate = passDt.getDate();
    //对时和分进行补零操作
    const passHours = formatDate(passDt.getHours());
    const passMinutes =formatDate( passDt.getMinutes());

    //now是现在时间的毫秒数
    const now = Date.now();
    const nowDt = new Date(now);
    const nowYears = nowDt.getFullYear();
    const nowMonths = nowDt.getMonth()+1;
    const nowDate = nowDt.getDate();
    //当是上一年或者更加之前的评论,返回的日期(与现在的时间相比较)
    if( nowYears>passYears ){
        return `${passYears}年${passMonths}月${passDate}日 ${passHours}:${passMinutes}`;
    }
    //当是今年的评论
    if( nowYears === passYears ) {
        return `${passMonths}月${passDate}日 ${passHours}:${passMinutes}`;
    }
    //当是今天的评论
    if( passYears === nowYears &&  passMonths === nowMonths &&  passDate === nowDate ) {
        return `${passHours}:${passMinutes}`;
    }
}


//格式化音乐播放时间,传入秒
export const getSongPlayerTime = (mill)=>{
    var theTime = parseInt(mill);// 秒
    var middle= 0;// 分

    if(theTime > 60) {
        middle= parseInt(theTime/60);
        theTime = parseInt(theTime%60);
        if(middle > 60) {
            middle= parseInt(middle%60);
        }
    }
    var result = ""+parseInt(theTime)+"秒";
    if(middle > 0) {
        result = ""+parseInt(middle)+"分"+result;
    }
    return result;
}
